<?php

/**
 * Contains a class to define a Zip object to describe a Zip code.
 *
 * PHP Version 5
 *
 * @category BuyLocal
 * @package  BuyLocal
 * @author   Kevin Fodness <kevin.fodness@gmail.com>
 * @author   Mike Pennisi <mpennisi@andrew.cmu.edu>
 * @author   Aaron Ryden <aryden@gmail.com>
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link     http://code.google.com/p/buylocalopensourcerensselaer/
 */

/**
 * A class to define a Zip object to describe a Zip code.
 *
 * @category BuyLocal
 * @package  BuyLocal
 * @author   Kevin Fodness <kevin.fodness@gmail.com>
 * @author   Mike Pennisi <mpennisi@andrew.cmu.edu>
 * @author   Aaron Ryden <aryden@gmail.com>
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link     http://code.google.com/p/buylocalopensourcerensselaer/
 */ 
class Zip
{
    /**
     * The ZIP code.
     *
     * @access public
     * @var string    Corresponds to zipcodes.zip
     */
    public $zip;
    
    /**
     * The city corresponding to the ZIP code.
     *
     * @access public
     * @var string    Corresponds to zipcodes.city
     */
    public $city;
    
    /**
     * The state corresponding to the ZIP code and city.
     *
     * @access public
     * @var string    Corresponds to zipcodes.state
     */
    public $state;
    
    /**
     * The latitude corresponding to the center of the ZIP code.
     *
     * @access public
     * @var float     Corresponds to zipcodes.latitude
     */
    public $latitude;
    
    /**
     * The longitude corresponding to the center of the ZIP code.
     *
     * @access public
     * @var float     Corresponds to zipcodes.longitude
     */
    public $longitude;

    /**
     * Constructor function.  Populates variables based on parameters.
     *
     * @param string $zip       The ZIP code.
     * @param string $city      The city the ZIP code is located in.
     * @param string $state     The state the ZIP code is located in.
     * @param float  $latitude  The latitude of the center of the ZIP code.
     * @param float  $longitude The longitude of the center of the ZIP code.
     *
     * @access public
     * @return null
     */
    public function __construct($zip, $city = null, $state = null,
        $latitude = null, $longitude = null
    ) {
        $this->zip       = $zip;
        $this->city      = $city;
        $this->state     = $state;
        $this->latitude  = $latitude;
        $this->longitude = $longitude;
    }

    /**
     * The clone function. Is called via the PHP5 'clone' keyword.
     * Since the 'clone' keyword automatically does a shallow copy of variables,
     * this code finishes the work and does a deep copy.
     *
     * @access public
     * @return null
     */
    public function __clone()
    {
        foreach ($this as $key => $val) {
            if (is_object($val) || is_array($val)) {
                $this->{$key} = unserialize(serialize($val));
            }
        }
    }
}

?>